package org.social.db.dao;

import com.sojoys.artifact.manager.DataSourceManager;
import java.sql.Connection;
import com.sojoys.artifact.build.data.base.BaseDao;
import java.util.ArrayList;
import com.sojoys.artifact.manager.JsonManager;
import java.sql.SQLException;
import com.sojoys.artifact.build.data.jdbc.SK_Query;
import com.google.common.collect.Lists;
import com.sojoys.artifact.tools.ToolMap;
import org.social.db.bean.GiftCode;
import org.apache.commons.dbutils.handlers.MapHandler;
import com.sojoys.artifact.tools.SK_Plus;
import java.sql.ResultSet;
import java.util.Map;
import javax.sql.DataSource;
import org.apache.commons.dbutils.handlers.MapListHandler;
import com.sojoys.artifact.constant.CreateTableEnum;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import org.apache.commons.dbutils.handlers.AbstractListHandler;
import org.apache.commons.dbutils.QueryRunner;
import com.xiaoleilu.hutool.log.Log;
import java.util.Set;
import com.sojoys.artifact.constant.ArtifactErrorCode;
import com.xiaoleilu.hutool.util.StrUtil;
import com.sojoys.artifact.tools.ToolError;
import org.apache.commons.dbutils.DbUtils;
import com.xiaoleilu.hutool.log.LogFactory;
import java.util.List;
import com.alibaba.fastjson.JSONObject;
import static org.social.db.StaticResource.GiftCodeResource.*;
import org.apache.commons.dbutils.ResultSetHandler;
import com.google.common.base.Joiner;
import static org.social.db.StaticResource.GiftCodeResource.*;
/**
 * 礼包码
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class GiftCodeDaoImpl implements BaseDao<Integer,GiftCode>{
	static Log log = LogFactory.get(GiftCodeDaoImpl.class);
	
	// 代理
	
	/**
	 * 私有化无参构造方法
	 */
	private GiftCodeDaoImpl() {}
	  
    private static final GiftCodeDaoImpl INSTANCE = new GiftCodeDaoImpl();  
    
    public static GiftCodeDaoImpl me() {  
        return INSTANCE;  
    }  
	
	public GiftCode insert(GiftCode giftCode){
		Connection conn = DataSourceManager.me().getMainConnection();
		return insert(giftCode,conn);
	}
	
	public GiftCode insert(GiftCode giftCode,Connection conn){
		return insert(giftCode,conn,TABLE_NAME);
	}
	
	public GiftCode insert(GiftCode giftCode,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insert(giftCode,conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public GiftCode insert(GiftCode giftCode,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return insert(giftCode,conn,tableName);
	}
	
	public GiftCode insert(GiftCode giftCode,Connection conn,String tableName){
		
		SK_Query sq = new SK_Query();
		String sql = "INSERT INTO " +tableName+ " (id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			int i = (int)sq.insert(conn,sql,giftCode.getId(),giftCode.getGiftPackageId(),giftCode.getName(),giftCode.getCode(),giftCode.getLimitCount(),giftCode.getPlatform(),giftCode.getChannelId(),giftCode.getStartTime(),giftCode.getEndTime(),giftCode.getGainLogByte(),giftCode.getRemark(),giftCode.getCreateDate(),giftCode.getModifiedDate());
			if(giftCode.getId()==0){
				giftCode.setId(i);
			}
			return i > 0 ? giftCode : null;
		} catch (Exception e) {
			log.error(e);
			return null;
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
	}
	
	public GiftCode insert(GiftCode giftCode,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insert(giftCode,conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}		
	}
	
	public int[] insertBatch(List<GiftCode> giftCodes){
		Connection conn = DataSourceManager.me().getMainConnection();
		return insertBatch(giftCodes,conn);
	}
	
	public int[] insertBatch(List<GiftCode> giftCodes,Connection conn){
		return insertBatch(giftCodes,conn,TABLE_NAME);
	}
	
	public int[] insertBatch(List<GiftCode> giftCodes,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(giftCodes,conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public int[] insertBatch(List<GiftCode> giftCodes,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return insertBatch(giftCodes,conn,tableName);
	}
	
	public int[] insertBatch(List<GiftCode> giftCodes,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "INSERT INTO " +tableName+ " (id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			int columnSize = 13;
			int size = giftCodes.size();
			Object[][] params = new Object[size][columnSize];
			for (int i = 0; i < size; i++) {
				params[i][0] =giftCodes.get(i).getId();
				params[i][1] =giftCodes.get(i).getGiftPackageId();
				params[i][2] =giftCodes.get(i).getName();
				params[i][3] =giftCodes.get(i).getCode();
				params[i][4] =giftCodes.get(i).getLimitCount();
				params[i][5] =giftCodes.get(i).getPlatform();
				params[i][6] =giftCodes.get(i).getChannelId();
				params[i][7] =giftCodes.get(i).getStartTime();
				params[i][8] =giftCodes.get(i).getEndTime();
				params[i][9] =giftCodes.get(i).getGainLogByte();
				params[i][10] =giftCodes.get(i).getRemark();
				params[i][11] =giftCodes.get(i).getCreateDate();
				params[i][12] =giftCodes.get(i).getModifiedDate();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 0 ? is : new int[]{};
		} catch (Exception e) {
			log.error(e);
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
	}
	
	public int[] insertBatch(List<GiftCode> giftCodes,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return insertBatch(giftCodes,conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}		
	}
	
	public GiftCode update(GiftCode giftCode){
		Connection conn = DataSourceManager.me().getMainConnection();
		return update(giftCode,conn);
	}
	
	public GiftCode update(GiftCode giftCode,Connection conn){
		return update(giftCode,conn,TABLE_NAME);
	}
	
	public GiftCode update(GiftCode giftCode,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return update(giftCode,conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public GiftCode update(GiftCode giftCode,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return update(giftCode,conn,tableName);
	}
	
	public GiftCode update(GiftCode giftCode,Connection conn,String tableName){
		List<GiftCode> giftCodes = new ArrayList<GiftCode>();
		giftCodes.add(giftCode);
		updateBatch(giftCodes,conn,tableName);
		return giftCode;
	}
	
	public GiftCode update(GiftCode giftCode,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return update(giftCode,conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public int[] updateBatch(List<GiftCode> giftCodes){
		Connection conn = DataSourceManager.me().getMainConnection();
		return updateBatch(giftCodes,conn);
	}
	
	public int[] updateBatch(List<GiftCode> giftCodes,Connection conn){
		return updateBatch(giftCodes,conn,TABLE_NAME);
	}
	
	public int[] updateBatch(List<GiftCode> giftCodes,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(giftCodes,conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public int[] updateBatch(List<GiftCode> giftCodes,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return updateBatch(giftCodes,conn,tableName);
	}
	
	public int[] updateBatch(List<GiftCode> giftCodes,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "UPDATE " +tableName+ " SET id = ?,gift_package_id = ?,name = ?,code = ?,limit_count = ?,platform = ?,channel_id = ?,start_time = ?,end_time = ?,gain_log = ?,remark = ?,create_date = ?,modified_date = ? WHERE id = ?";
		try {
			int columnSize = 13;
			int size = giftCodes.size();
			Object[][] params = new Object[size][columnSize + 1];
			for (int i = 0; i < size; i++) {
				params[i][0] =giftCodes.get(i).getId();
				params[i][1] =giftCodes.get(i).getGiftPackageId();
				params[i][2] =giftCodes.get(i).getName();
				params[i][3] =giftCodes.get(i).getCode();
				params[i][4] =giftCodes.get(i).getLimitCount();
				params[i][5] =giftCodes.get(i).getPlatform();
				params[i][6] =giftCodes.get(i).getChannelId();
				params[i][7] =giftCodes.get(i).getStartTime();
				params[i][8] =giftCodes.get(i).getEndTime();
				params[i][9] =giftCodes.get(i).getGainLogByte();
				params[i][10] =giftCodes.get(i).getRemark();
				params[i][11] =giftCodes.get(i).getCreateDate();
				params[i][12] =giftCodes.get(i).getModifiedDate();
				params[i][columnSize] =giftCodes.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 0 ? is : new int[]{};
		} catch (Exception e) {
			log.error(e);
			return new int[]{};
		} finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
	}
	
	public int[] updateBatch(List<GiftCode> giftCodes,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return updateBatch(giftCodes,conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}		
	}
	
	public boolean delete(GiftCode giftCode){
		Connection conn = DataSourceManager.me().getMainConnection();
		return delete(giftCode,conn);
	}
	
	public boolean delete(GiftCode giftCode,Connection conn){
		return delete(giftCode,conn,TABLE_NAME);
	}
	
	public boolean delete(GiftCode giftCode,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return delete(giftCode,conn);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	public boolean delete(GiftCode giftCode,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return delete(giftCode,conn,tableName);
	}
	
	public boolean delete(GiftCode giftCode,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int i = run.update(conn,sql, giftCode.getId());
			return i > 0 ? true : false;
		} catch (Exception e) {
			log.error(e);
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return false;
			}
		}
	}
	
	public boolean delete(GiftCode giftCode,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return delete(giftCode,conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	
	public boolean deleteBatch(List<GiftCode> giftCodes){
		Connection conn = DataSourceManager.me().getMainConnection();
		return deleteBatch(giftCodes,conn);
	}
	
	public boolean deleteBatch(List<GiftCode> giftCodes,Connection conn){
		return deleteBatch(giftCodes,conn,TABLE_NAME);
	}
	
	public boolean deleteBatch(List<GiftCode> giftCodes,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(giftCodes,conn);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	public boolean deleteBatch(List<GiftCode> giftCodes,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return deleteBatch(giftCodes,conn,tableName);
	}
	
	public boolean deleteBatch(List<GiftCode> giftCodes,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DELETE FROM " + tableName + " WHERE id = ?";
		try {
			int size = giftCodes.size();
			Object[][] params = new Object[size][1];
			for (int i = 0; i < size; i++) {
				params[i][0] = giftCodes.get(i).getId();
			}
			int[] is = run.batch(conn,sql,params);
			return is.length > 0;
		} catch (Exception e) {
			log.error(e);
			return false;
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return false;
			}
		}
	}
	
	public boolean deleteBatch(List<GiftCode> giftCodes,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return deleteBatch(giftCodes,conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}

	/**
	 * 根据( id ) 查询
	 */
	public GiftCode getById(int id){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getById(id, conn);
	}
	
	public GiftCode getById(int id,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getById(id, conn,tableName);
	}
	public List<GiftCode> getIn(Set<Integer> ids){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getIn(ids, conn);
	}
	
	public List<GiftCode> getIn(Set<Integer> ids,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getIn(ids, conn,tableName);
	}
	/**
	 * 根据( code ) 查询
	 */
	public GiftCode getByCode(String code){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getByCode(code, conn);
	}
	
	public GiftCode getByCode(String code,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getByCode(code, conn,tableName);
	}
	/**
	 * 根据( gift_package_id ) 查询
	 */
	public List<GiftCode> getByGiftPackageId(int giftPackageId){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getByGiftPackageId(giftPackageId, conn);
	}
	
	public List<GiftCode> getByGiftPackageId(int giftPackageId,String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getByGiftPackageId(giftPackageId, conn,tableName);
	}
	
	public List<GiftCode> getByPageGiftPackageId(int giftPackageId,int page,int pageSize){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getByPageGiftPackageId(giftPackageId, conn,page,pageSize);
	}
	
	public List<GiftCode> getByPageGiftPackageId(int giftPackageId,String tableName,int page,int pageSize){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getByPageGiftPackageId(giftPackageId, conn,tableName,page,pageSize);
	}
	
	//Connection
	/**
	 * 根据( id ) 查询
	 */
	public GiftCode getById(int id,Connection conn){
		return getById(id,conn,TABLE_NAME);
	}
	
	public GiftCode getById(int id,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date FROM " + tableName + " WHERE " + "id = ? ORDER BY id ASC LIMIT 1";
		GiftCode giftCode = null; 
		try {
			giftCode = run.query(conn,sql, new GiftCodeHandler(), id);
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return giftCode;
	}
	public List<GiftCode> getIn(Set<Integer> ids,Connection conn){
		return getIn(ids,conn,TABLE_NAME);
	}
	
	public List<GiftCode> getIn(Set<Integer> ids,Connection conn,String tableName){
		List<GiftCode> giftCodes = Lists.newArrayList();
		if(ids.isEmpty()) return giftCodes;
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date FROM " + tableName + " WHERE " + "id in (%s) ORDER BY id ASC";
		sql = String.format(sql, Joiner.on(",").join(ids));
		try {
			giftCodes = run.query(conn,sql, new GiftCodeListHandler());
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return giftCodes;
	}
	/**
	 * 根据( code ) 查询
	 */
	public GiftCode getByCode(String code,Connection conn){
		return getByCode(code,conn,TABLE_NAME);
	}
	
	public GiftCode getByCode(String code,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date FROM " + tableName + " WHERE " + "code = ? ORDER BY id ASC LIMIT 1";
		GiftCode giftCode = null; 
		try {
			giftCode = run.query(conn,sql, new GiftCodeHandler(), code);
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return giftCode;
	}
	/**
	 * 根据( gift_package_id ) 查询
	 */
	public List<GiftCode> getByGiftPackageId(int giftPackageId,Connection conn){
		return getByGiftPackageId(giftPackageId,conn,TABLE_NAME);
	}
	
	public List<GiftCode> getByGiftPackageId(int giftPackageId,Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date FROM " + tableName + " WHERE " + "gift_package_id = ? ORDER BY id ASC";
		List<GiftCode> giftCodes = Lists.newArrayList();
		try {
			giftCodes = run.query(conn, sql, new GiftCodeListHandler(), giftPackageId);
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return giftCodes;
	}
	
	//-----------------------------------page-----------------------------------
	public List<GiftCode> getByPageGiftPackageId(int giftPackageId,Connection conn,int page,int pageSize){
		return getByPageGiftPackageId(giftPackageId,conn,TABLE_NAME,page,pageSize);
	}
	
	public List<GiftCode> getByPageGiftPackageId(int giftPackageId,Connection conn,String tableName,int page,int pageSize){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageSize);
		String sql = "SELECT id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date FROM " + tableName + " WHERE " + "gift_package_id = ? ORDER BY id ASC LIMIT " + page + " , " +pageSize;
		List<GiftCode> giftCodes = Lists.newArrayList();
		try {
			giftCodes = run.query(conn, sql, new GiftCodeListHandler(), giftPackageId);
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return giftCodes;
	}
	
	//DataSource
	/**
	 * 根据( id ) 查询
	 */
	public GiftCode getById(int id,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public GiftCode getById(int id,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getById(id, conn, tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	public List<GiftCode> getIn(Set<Integer> ids,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getIn(ids, conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public List<GiftCode> getIn(Set<Integer> ids,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getIn(ids, conn, tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	/**
	 * 根据( code ) 查询
	 */
	public GiftCode getByCode(String code,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByCode(code, conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public GiftCode getByCode(String code,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByCode(code, conn, tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	/**
	 * 根据( gift_package_id ) 查询
	 */
	public List<GiftCode> getByGiftPackageId(int giftPackageId,DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getByGiftPackageId(giftPackageId, conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public List<GiftCode> getByGiftPackageId(int giftPackageId,DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getByGiftPackageId(giftPackageId, conn, tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	//-----------------------------------page-----------------------------------
	public List<GiftCode> getByPageGiftPackageId(int giftPackageId,DataSource ds,int page,int pageSize){
		try {
			Connection conn = ds.getConnection();
			return getByPageGiftPackageId(giftPackageId, conn,page,pageSize);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public List<GiftCode> getByPageGiftPackageId(int giftPackageId,DataSource ds,String tableName,int page,int pageSize){
		try {
			Connection conn = ds.getConnection();
			return getByPageGiftPackageId(giftPackageId, conn,page,pageSize);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	
	public List<GiftCode> getAll(){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getAll(conn);
	}
	
	public List<GiftCode> getAll(Connection conn){
		return getAll(conn,TABLE_NAME);
	}
	
	public List<GiftCode> getAll(DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public List<GiftCode> getAll(String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getAll(conn,tableName);
	}
	
	public List<GiftCode> getAll(Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date FROM " + tableName + " ORDER BY id ASC";
		List<GiftCode> giftCodes = Lists.newArrayList();
		try {
			giftCodes = run.query(conn, sql, new GiftCodeListHandler());
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return giftCodes;
	}
	
	public List<GiftCode> getAll(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getAll(conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}		
	}
	
	public List<GiftCode> getAllPage(int page,int pageSize){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getAllPage(conn,page,pageSize);
	}
	
	public List<GiftCode> getAllPage(Connection conn,int page,int pageSize){
		return getAllPage(conn,TABLE_NAME,page,pageSize);
	}
	
	public List<GiftCode> getAllPage(DataSource ds,int page,int pageSize){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,page,pageSize);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public List<GiftCode> getAllPage(String tableName,int page,int pageSize){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getAllPage(conn,tableName,page,pageSize);
	}
	
	public List<GiftCode> getAllPage(Connection conn,String tableName,int page,int pageSize){
		QueryRunner run = new QueryRunner();
		page = ((page-1) * pageSize);
		String sql = "SELECT id,gift_package_id,name,code,limit_count,platform,channel_id,start_time,end_time,gain_log,remark,create_date,modified_date FROM " + tableName + " ORDER BY id ASC LIMIT " + page + " , " +pageSize;
		List<GiftCode> giftCodes = Lists.newArrayList();
		try {
			giftCodes = run.query(conn, sql, new GiftCodeListHandler());
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return giftCodes;
	}
	
	public List<GiftCode> getAllPage(DataSource ds,String tableName,int page,int pageSize){
		try {
			Connection conn = ds.getConnection();
			return getAllPage(conn,tableName,page,pageSize);
		} catch (Exception e) {
			log.error(e);
			return null;
		}		
	}
	
	public boolean truncate(){
		Connection conn = DataSourceManager.me().getMainConnection();
		return truncate(conn);
	}
	
	public boolean truncate(Connection conn){
		return truncate(conn,TABLE_NAME);
	}
	
	public boolean truncate(DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return truncate(conn);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	public boolean truncate(String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return truncate(conn,tableName);
	}
	
	public boolean truncate(Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "TRUNCATE " + tableName;
		try {
			run.update(conn, sql);
			return true;
		} catch (Exception e) {
			log.error(e);
			return false;
		} finally {
			try {
				DbUtils.close(conn);
			} catch (Exception e1) {
				log.error(e1);
				return false;
			}
		}
	}
	
	public boolean truncate(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return truncate(conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	// 执行自定义查询sql
	public List<Map<String,Object>> executeQuerySql(String sql){
		Connection conn = DataSourceManager.me().getMainConnection();
		return executeQuerySql(conn,sql);
	}
	
	public List<Map<String,Object>> executeQuerySql(Connection conn,String sql){
		return executeQuerySql(conn,TABLE_NAME,sql);
	}
	
	public List<Map<String,Object>> executeQuerySql(DataSource ds,String sql){
		try {
			Connection conn = ds.getConnection();
			return executeQuerySql(conn,sql);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	
	public List<Map<String,Object>> executeQuerySql(String tableName,String sql){
		Connection conn = DataSourceManager.me().getMainConnection();
		return executeQuerySql(conn,tableName);
	}
	
	public List<Map<String,Object>> executeQuerySql(Connection conn,String tableName,String sql){
		QueryRunner run = new QueryRunner();
		ToolError.isAndTrue(ArtifactErrorCode.SQL_PERMISSIONS_ERROR, !StrUtil.startWithIgnoreCase(sql, "SELECT"));
		List<Map<String,Object>> list = Lists.newArrayList();
		try {
			list = run.query(conn,sql, new MapListHandler());
		} catch (Exception e) {
			log.error(e);
		}finally {
			try{
				DbUtils.close(conn);
			}catch (Exception e1) {
				log.error(e1);
				return null;
			}
		}
		return list;
	}
	/**
	public List<Map<String,Object>> executeQuerySql(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return executeQuerySql(conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return null;
		}
	}
	*/
	
	//
	
	public int getLastId(){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getLastId(conn);
	}
	
	public int getLastId(Connection conn){
		return getLastId(conn,TABLE_NAME);
	}
	
	public int getLastId(DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return getLastId(conn);
		} catch (Exception e) {
			log.error(e);
			return 0;
		}
	}
	
	public int getLastId(String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return getLastId(conn,tableName);
	}
	
	public int getLastId(Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "SELECT id FROM " + tableName + " ORDER BY id DESC LIMIT 1";
		try {
			Map result = run.query(conn, sql, new MapHandler());
			return result == null ? 0 : ToolMap.getInt("id",result,0);
		} catch (Exception e) {
			log.error(e);
			return 0;
		} finally {
			try {
				DbUtils.close(conn);
			} catch (Exception e1) {
				log.error(e1);
				return 0;
			}
		}
	}
	
	public int getLastId(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return getLastId(conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return 0;
		}
	}
	//
	
	//Drop Table
	public boolean drop(){
		Connection conn = DataSourceManager.me().getMainConnection();
		return drop(conn);
	}
	
	public boolean drop(Connection conn){
		return drop(conn,TABLE_NAME);
	}
	
	public boolean drop(DataSource ds){
		try {
			Connection conn = ds.getConnection();
			return drop(conn);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	public boolean drop(String tableName){
		Connection conn = DataSourceManager.me().getMainConnection();
		return drop(conn,tableName);
	}
	
	public boolean drop(Connection conn,String tableName){
		QueryRunner run = new QueryRunner();
		String sql = "DROP TABLE " + tableName;
		try {
			run.update(conn, sql);
			return true;
		} catch (Exception e) {
			log.error(e);
			return false;
		} finally {
			try {
				DbUtils.close(conn);
			} catch (Exception e1) {
				log.error(e1);
				return false;
			}
		}
	}
	
	public boolean drop(DataSource ds,String tableName){
		try {
			Connection conn = ds.getConnection();
			return drop(conn,tableName);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	
	//create
	public boolean createTable(CreateTableEnum type){
		Connection conn = DataSourceManager.me().getMainConnection();
		return createTable(conn,type);
	}
	
	public boolean createTable(Connection conn,CreateTableEnum type){
		return createTable(conn,TABLE_NAME,type);
	}
	
	public boolean createTable(DataSource ds,CreateTableEnum type){
		try {
			Connection conn = ds.getConnection();
			return createTable(conn,type);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	public boolean createTable(String tableName,CreateTableEnum type){
		Connection conn = DataSourceManager.me().getMainConnection();
		return createTable(conn,tableName,type);
	}
	
	public boolean createTable(Connection conn,String tableName,CreateTableEnum type){
		QueryRunner run = new QueryRunner();
		SK_Plus plus = SK_Plus.b("CREATE TABLE IF NOT EXISTS `", tableName,"` (");
		plus.a("  `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '',");	
		plus.a("  `gift_package_id` INT(11) NOT NULL  COMMENT 'remarks=礼包ID',");	
		plus.a("  `name` VARCHAR(45)   COMMENT 'remarks=礼包码名称',");	
		plus.a("  `code` VARCHAR(45)   COMMENT 'remarks=礼包码',");	
		plus.a("  `limit_count` INT(11)   COMMENT 'remarks=限定次数',");	
		plus.a("  `platform` VARCHAR(45)   COMMENT 'remarks=平台',");	
		plus.a("  `channel_id` INT(11)   COMMENT 'remarks=渠道',");	
		plus.a("  `start_time` DATETIME   COMMENT 'remarks=开始时间',");
		plus.a("  `end_time` DATETIME   COMMENT 'remarks=结束时间',");
		plus.a("  `gain_log` BLOB(65535)   COMMENT 'remarks=已领记录',");	
		plus.a("  `remark` VARCHAR(200)   COMMENT 'remarks=描述',");	
		plus.a("  `create_date` DATETIME   COMMENT '',");
		plus.a("  `modified_date` DATETIME   COMMENT '',");
		plus.a("  PRIMARY KEY (`id`),");
		if (CreateTableEnum.LOGIC.equals(type) || CreateTableEnum.DESIGN.equals(type)) {
			plus.a("  UNIQUE KEY `code` (`code`),");
			plus.a("  KEY `fk_gift_code_gift_package_idx` (`gift_package_id`),");
			
		}
		if (CreateTableEnum.DESIGN.equals(type)) {
			plus.a("  CONSTRAINT `fk_gift_code_gift_package` FOREIGN KEY (`gift_package_id`) REFERENCES `gift_package` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,");
		}
		String sql = plus.e();
		sql = StrUtil.subPre(sql, sql.lastIndexOf(StrUtil.C_COMMA));
		sql+=") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 COMMENT='remarks=礼包码';";
		try {
			run.update(conn, sql);
			return true;
		} catch (Exception e) {
			log.error(e);
			return false;
		} finally {
			try {
				DbUtils.close(conn);
			} catch (Exception e1) {
				log.error(e1);
				return false;
			}
		}
	}
	
	public boolean createTable(DataSource ds,String tableName,CreateTableEnum type){
		try {
			Connection conn = ds.getConnection();
			return createTable(conn,tableName,type);
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@SuppressWarnings("unchecked")
	public List<Map<String,Object>> getColumnsInfo(){
		SK_Plus sp = SK_Plus.newSK_Plus();
		sp.a("[");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"NO\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"id\",\"NULLABLE\":0,\"REMARKS\":\"\",\"DECIMAL_DIGITS\":0,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"YES\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":1,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":4,\"TYPE_NAME\":\"INT\",\"COLUMN_SIZE\":11}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"NO\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"gift_package_id\",\"NULLABLE\":0,\"REMARKS\":\"remarks=礼包ID\",\"DECIMAL_DIGITS\":0,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":2,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":4,\"TYPE_NAME\":\"INT\",\"COLUMN_SIZE\":11}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"name\",\"NULLABLE\":1,\"REMARKS\":\"remarks=礼包码名称\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":135,\"ORDINAL_POSITION\":3,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":12,\"TYPE_NAME\":\"VARCHAR\",\"COLUMN_SIZE\":45}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"code\",\"NULLABLE\":1,\"REMARKS\":\"remarks=礼包码\n\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":135,\"ORDINAL_POSITION\":4,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":12,\"TYPE_NAME\":\"VARCHAR\",\"COLUMN_SIZE\":45}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"limit_count\",\"NULLABLE\":1,\"REMARKS\":\"remarks=限定次数\",\"DECIMAL_DIGITS\":0,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":5,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":4,\"TYPE_NAME\":\"INT\",\"COLUMN_SIZE\":11}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"platform\",\"NULLABLE\":1,\"REMARKS\":\"remarks=平台\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":135,\"ORDINAL_POSITION\":6,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":12,\"TYPE_NAME\":\"VARCHAR\",\"COLUMN_SIZE\":45}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"channel_id\",\"NULLABLE\":1,\"REMARKS\":\"remarks=渠道\",\"DECIMAL_DIGITS\":0,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":7,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":4,\"TYPE_NAME\":\"INT\",\"COLUMN_SIZE\":11}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"start_time\",\"NULLABLE\":1,\"REMARKS\":\"remarks=开始时间\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":8,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":93,\"TYPE_NAME\":\"DATETIME\",\"COLUMN_SIZE\":19}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"end_time\",\"NULLABLE\":1,\"REMARKS\":\"remarks=结束时间\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":9,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":93,\"TYPE_NAME\":\"DATETIME\",\"COLUMN_SIZE\":19}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"gain_log\",\"NULLABLE\":1,\"REMARKS\":\"remarks=已领记录\ntype=Map\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":65535,\"ORDINAL_POSITION\":10,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":-4,\"TYPE_NAME\":\"BLOB\",\"COLUMN_SIZE\":65535}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"remark\",\"NULLABLE\":1,\"REMARKS\":\"remarks=描述\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":600,\"ORDINAL_POSITION\":11,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":12,\"TYPE_NAME\":\"VARCHAR\",\"COLUMN_SIZE\":200}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"create_date\",\"NULLABLE\":1,\"REMARKS\":\"\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":12,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":93,\"TYPE_NAME\":\"DATETIME\",\"COLUMN_SIZE\":19}").a(",");
       	sp.a("{\"SCOPE_TABLE\":null,\"TABLE_CAT\":\"dal_social_design\",\"BUFFER_LENGTH\":65535,\"IS_NULLABLE\":\"YES\",\"TABLE_NAME\":\"gift_code\",\"COLUMN_DEF\":null,\"SCOPE_CATALOG\":null,\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"modified_date\",\"NULLABLE\":1,\"REMARKS\":\"\",\"DECIMAL_DIGITS\":null,\"NUM_PREC_RADIX\":10,\"SQL_DATETIME_SUB\":0,\"IS_GENERATEDCOLUMN\":\"NO\",\"IS_AUTOINCREMENT\":\"NO\",\"SQL_DATA_TYPE\":0,\"CHAR_OCTET_LENGTH\":null,\"ORDINAL_POSITION\":13,\"SCOPE_SCHEMA\":null,\"SOURCE_DATA_TYPE\":null,\"DATA_TYPE\":93,\"TYPE_NAME\":\"DATETIME\",\"COLUMN_SIZE\":19}").a(",");
        sp.a("]");
        return JsonManager.me().getJson().parse(sp.e(), List.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<Map<String,Object>> getIndexsInfo(){
		SK_Plus sp = SK_Plus.newSK_Plus();
		sp.a("[");
       	sp.a("{\"NON_UNIQUE\":false,\"TABLE_CAT\":\"dal_social_design\",\"PAGES\":null,\"TABLE_NAME\":\"gift_code\",\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"id\",\"INDEX_NAME\":\"PRIMARY\",\"ASC_OR_DESC\":\"A\",\"INDEX_QUALIFIER\":\"dal_social_design\",\"ORDINAL_POSITION\":1,\"CARDINALITY\":0,\"FILTER_CONDITION\":null,\"TYPE\":3}").a(",");
       	sp.a("{\"NON_UNIQUE\":false,\"TABLE_CAT\":\"dal_social_design\",\"PAGES\":null,\"TABLE_NAME\":\"gift_code\",\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"code\",\"INDEX_NAME\":\"code\",\"ASC_OR_DESC\":\"A\",\"INDEX_QUALIFIER\":\"dal_social_design\",\"ORDINAL_POSITION\":1,\"CARDINALITY\":0,\"FILTER_CONDITION\":null,\"TYPE\":3}").a(",");
       	sp.a("{\"NON_UNIQUE\":true,\"TABLE_CAT\":\"dal_social_design\",\"PAGES\":null,\"TABLE_NAME\":\"gift_code\",\"TABLE_SCHEM\":null,\"COLUMN_NAME\":\"gift_package_id\",\"INDEX_NAME\":\"fk_gift_code_gift_package_idx\",\"ASC_OR_DESC\":\"A\",\"INDEX_QUALIFIER\":\"dal_social_design\",\"ORDINAL_POSITION\":1,\"CARDINALITY\":0,\"FILTER_CONDITION\":null,\"TYPE\":3}").a(",");
        sp.a("]");
        return JsonManager.me().getJson().parse(sp.e(), List.class);
	}
//自定义内容起始位置
class GiftCodeHandler implements ResultSetHandler<GiftCode>{
	@Override
	public GiftCode handle(ResultSet rs) throws SQLException {
		return rs.next() ? GiftCode.builder().createForResultSet(rs).syncIndexValues() : null ;
	}
}

class GiftCodeListHandler extends AbstractListHandler<GiftCode>{
	@Override
	protected GiftCode handleRow(ResultSet rs) throws SQLException {
		return GiftCode.builder().createForResultSet(rs).syncIndexValues();
	}
}

//自定义内容结束位置
}

